/**
 * 日期格式化.
 * 
 * 参数：日期字符、目标格式、输出对象
 * 输出：目标日期
 * 
 * 提取日期字符中所有的数字，将数字按格式提取；
 * 
 */

var DateFormat = function () {
	
	var today = new Date();
	
	var year = today.getFullYear();
	var month = '';
	var day = '';
	var hour = '';
	var minute = '';
	var second = '';
	
	//日期字符
	var str = '';
	
	//日期格式
	var pattern = 'yyyy-MM-dd HH:mm:ss';
	
	//字符中的数字数组
	var number = '';
	
	//正则表达式提取传入字符中的数字
	var drawNumber = function(str){
		number=str.match(/\d/g);
	};
	
	//对日期进行拆分
	var split = function(){
		if(number.length >= 4){
			year = number[0]+number[1]+number[2]+number[3];
		}
		if(number.length >= 6){
			month = number[4]+number[5];
		}
		if(number.length >= 8){
			day = number[6]+number[7];
		}
		if(number.length >= 10){
			hour = number[8]+number[9];
		}
		if(number.length >= 12){
			minute = number[10]+number[11];
		}
		if(number.length >= 14){
			second = number[12]+number[13];
		}
	};
	
	return{
		setPattern:function(ptn){
			pattern = ptn;
		},
		
		format: function (targer) {
			year = today.getFullYear();
			month = '01';
			day = '01';
			hour = '00';
			minute = '00';
			second = '00';
			drawNumber(targer.val());
			split();
			targer.val(pattern.replace(/yyyy/, year).replace(/MM/, month).replace(/dd/, day).replace(/HH/, hour).replace(/mm/, minute).replace(/ss/, second));
        },
        
	};
}();